<%= render('kotlin/package.erb') %>

<%  has_string = entity.cases.all? { |c| !c.string.nil? } -%>
actual enum class <%= entity.name %>(
    val jsValue: Js<%= entity.name %>,
<%  if has_string -%>
    actual val stringValue: String,
<%  end -%>
) {
<%# Cases -%>
<%  entity.cases.each_with_index do |c, i| -%>
<%  if has_string -%>
    <%= c.name %>(WalletCore.Instance.<%= entity.name %>.<%= KotlinHelper.fix_name(WasmCppHelper.format_name(c.name)) %>, <%= c.string %>),
<%  else -%>
    <%= c.name %>(WalletCore.Instance.<%= entity.name %>.<%= KotlinHelper.fix_name(WasmCppHelper.format_name(c.name)) %>),
<%  end -%>
<%  end -%>
    ;

    actual val value: UInt
        get() = jsValue.value.toInt().toUInt()
<%# Property declarations -%>
<%- entity.properties.each do |property| -%>

    actual val <%= KotlinHelper.format_name(property.name) %><%= KotlinHelper.return_type(property.return_type) %>
        get() = <%= KotlinHelper.convert_calling_return_type_js(property.return_type, "WalletCore.Instance.#{entity.name}Ext.#{WasmCppHelper.function_name(entity: entity, function: property)}(jsValue)") %>
<%- end -%>
<%# Method declarations -%>
<%- entity.methods.each do |method| -%>
<%-   next if method.name.start_with?('Delete') -%>

    actual fun <%= KotlinHelper.format_name(method.name) %>(<%= KotlinHelper.parameters(method.parameters.drop(1)) %>)<%= KotlinHelper.return_type(method.return_type) %> =
        <%= KotlinHelper.convert_calling_return_type_js(method.return_type, "WalletCore.Instance.#{entity.name}Ext.#{WasmCppHelper.function_name(entity: entity, function: method)}(jsValue#{', ' if not method.parameters.one?}#{KotlinHelper.calling_parameters_js(method.parameters.drop(1))})") %>
<%- end -%>
<%# Value -%>
<%  if entity.cases.any? { |e| !e.value.nil? } -%>

    actual companion object {
        actual fun fromValue(value: UInt): <%= entity.name %>? =
            values().first { it.value == value }

        fun fromValue(jsValue: Js<%= entity.name %>): <%= entity.name %> =
            values().first { it.jsValue.value == jsValue.value }
    }
<%  end -%>
}
